package com.kqb.sgadmin.service.pipeline.create.handler;

import cn.hutool.core.bean.BeanUtil;
import com.kqb.sgadmin.model.Admin;
import com.kqb.sgadmin.service.AdminService;
import com.kqb.sgadmin.service.pipeline.create.AdminCreateHandler;
import com.kqb.sgadmin.service.pipeline.create.context.AdminCreateContext;
import com.kqb.sgcommon.base.exception.BusinessException;
import com.kqb.sgcommon.base.utils.ThrowUtils;
import jakarta.annotation.Resource;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 杉果树皮
 */
@Component
@Order(999)
public class SaveUserHandler implements AdminCreateHandler {

    @Resource
    private AdminService adminService;

    @Override
    public void handle(AdminCreateContext context) {
        boolean save = adminService.save(BeanUtil.toBean(context, Admin.class));
        ThrowUtils.throwNotIf(save, BusinessException.of("保存管理员失败"));
    }
}
